package service.impl;

import mapper.IFoodMapper;
import org.apache.ibatis.session.SqlSession;

import pojo.Food;
import service.IFoodService;
import utils.MybatisUtils;
import vo.ResponseVo;

import java.util.List;

public class FoodService implements IFoodService {

    @Override
    public ResponseVo<List<Food>> getFoodList() {

        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IFoodMapper mapper =sqlSession.getMapper(IFoodMapper.class);
        List<Food> list=mapper.getFoodList();
        //2.调用mapper层相应方法
        ResponseVo<List<Food>> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);
        //3.封装ResponseVo
        return responseVo;
    }
    @Override
    public ResponseVo<List<Food>> findFoodById(Integer id) {
        SqlSession sqlSession = MybatisUtils.getSqlSession();
        IFoodMapper mapper =sqlSession.getMapper(IFoodMapper.class);
        List<Food> list=mapper.findFoodById(id);
        //2.调用mapper层相应方法
        ResponseVo<List<Food>> responseVo=new ResponseVo<>();

        responseVo.setFlag(true);
        responseVo.setMessage("查询成功");
        responseVo.setResult(list);
        //3.封装ResponseVo
        return responseVo;
    }
}
